﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://wpfimageviewer.codeplex.com
using System;
using System.ComponentModel;
using AForge.Imaging.Filters;
using BrainTechLLC;
using BrainTechLLC.ImageOperators;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.Drawing;
using AForge.Imaging;
using System.Diagnostics;
using BrainTechLLC.ImageOperatorsNonAForgeDependent;

namespace BrainTechLLC.FilterExtensions
{
    [Serializable]
    public class CalculationInstance : BaseNotifyPropertyChanged, INotifyPropertyChanged
    {
        public ImageCalculation Calculation;        
        public double Result;
        public double CallCounter;

        public CalculationInstance() { }

        public CalculationInstance(ImageCalculation calc)
        {
            Calculation = calc;
            Result = 0.0D;
            CallCounter = 0.0D;
        }

        public void Calculate(Color c, int x, int y)
        {
            CallCounter += 1.0D;
            Result += Calculation.CalcAction(this, c, x, y);
        }

        public double GetAverageResult()
        {
            if (CallCounter == 0)
                return 0.0D;

            return Result / CallCounter;
        }

        public double GetTotalResult()
        {
            return Result;
        }
        
        public override string ToString()
        {
            return string.Format("Sum: {0:N0}, Count: {1:N0}, Average: {2:N0}", GetTotalResult(), CallCounter, GetAverageResult());
        }
    }
}

